#!/usr/bin/perl
################################################################################
#
# Creates a Sword "conf" file.
#
#   swordConfCreator.pl <outputFolder> <isoCode>
#
# The file has the name <isoCode>.conf (isoCode capitalised) and is created
# in a folder called mods.d below the output folder.
################################################################################

#-------------------------------------------------------------------------------
use strict;
use warnings;
use Cwd;
use File::Basename;
use File::Copy;
use File::Find;
use File::Spec;
use File::Path;



#-------------------------------------------------------------------------------
if (2 != scalar @ARGV) { print "Usage: swordConfCreator.pl <outputFolder> <isoCode>"; die; }
if (! -e $ARGV[0]) { die "Output folder does not exist"; }
if (lc($ARGV[0]) !~ /sword/) { die "Invalid arguments"; }
    


#-------------------------------------------------------------------------------
my $isoCode = uc($ARGV[1]);
my $outputFolder = $ARGV[0] . "/mods.d";
my $outputFile = $outputFolder . "/" . $isoCode . ".conf";

rmtree($outputFolder);
mkdir $outputFolder;
open(MYFILE, ">>$outputFile");
  print MYFILE "[$isoCode]\n";
  print MYFILE "DataPath=./modules/texts/rawtext/$isoCode/\n";
  print MYFILE "Description=Test\n";
  print MYFILE "ModDrv=RawText\n";
  print MYFILE "SourceType=OSIS\n";
  print MYFILE "Encoding=UTF-8\n";
  print MYFILE "Lang=$isoCode\n";
close(MYFILE);



#-------------------------------------------------------------------------------
print "Sword conf file created successfully\n";
